import requests

member_url = "https://www.yaozh.com/member/"
login_url = "https://www.yaozh.com/login/"

header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
}

# # 1.代码登录
# login_form_data = {
#     "username": "lucky_yu",
#     "pwd": "199213xiao..",
#     "formhash": "1DABC55C63",
#     "backurl": "https%253A%252F%252Fwww.yaozh.com%252F"
# }
#
# login_response = requests.post(login_url, headers=header, data=login_form_data)
#
# # 2.登录成功后用cookies访问目标数据
# response = requests.get(member_url, headers=header, cookies=login_response.cookies)  #获取返回回来的cookies
# data = response.content.decode('utf-8')
#
# with open('cookies.html', mode='w', encoding='utf-8') as file:
#     file.write(data)



#session: 在一个会话里面
#使用session 自动保存cookies === cookiesJar
session = requests.Session()
# 1.代码登录
login_form_data = {
    "username": "lucky_yu",
    "pwd": "199213xiao..",
    "formhash": "1DABC55C63",
    "backurl": "https%253A%252F%252Fwww.yaozh.com%252F"
}

login_response = session.post(login_url, headers=header, data=login_form_data)

# 2.登录成功后用cookies访问目标数据
response = session.get(member_url, headers=header)
data = response.content.decode('utf-8')

with open('cookies.html', mode='w', encoding='utf-8') as file:
    file.write(data)


